package com.cskaoyan.service.wxgoods;

import com.cskaoyan.bean.po.ohter.MarketCategory;
import com.cskaoyan.bean.po.ohter.MarketCategoryExample;
import com.cskaoyan.bean.vo.category.CategoryListVo;
import com.cskaoyan.bean.vo.wxgoods.CatalogCurrentVo;
import com.cskaoyan.bean.vo.wxgoods.CatalogIndexVo;
import com.cskaoyan.mapper.MarketCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Ajun de BBC
 * @Date 2022/7/20 22:40
 * @Version 1.5
 */
@Service
public class WxCatalogServiceImpl implements WxCatalogService {

    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    /**
     *@Description : 分类页面的显示
     *@Param :
     *@Return :
     */
    @Override
    public CatalogIndexVo catalogIndex() {
        //查询level级别是L1的所有类目
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        marketCategoryExample.setOrderByClause("sort_order ASC");
        marketCategoryExample.createCriteria().andLevelEqualTo("L1");
        List<MarketCategory> categoryList = marketCategoryMapper.selectByExample(marketCategoryExample);
        MarketCategory marketCategory = categoryList.get(0);

        //显示第一个L1类目
        MarketCategory currentCategory = marketCategoryMapper.selectByPrimaryKey(marketCategory.getId());

        //显示该L1级类目下的所有L2类目
        MarketCategoryExample categoryExampleL2 = new MarketCategoryExample();
        categoryExampleL2.createCriteria().andPidEqualTo(currentCategory.getId());
        List<MarketCategory> currentSubCategory = marketCategoryMapper.selectByExample(categoryExampleL2);

        CatalogIndexVo catalogIndexVo = new CatalogIndexVo(currentCategory,categoryList,currentSubCategory);
        return catalogIndexVo;
    }


    /**
     *@Description : 分类页面显示指定类目
     *@Param :
     *@Return :
     */
    @Override
    public CatalogCurrentVo catalogCurrent(Integer id) {
        //查询到id对应的L1级类目所有信息
        MarketCategory marketCategory = marketCategoryMapper.selectByPrimaryKey(id);
        //查询到该L1类目下的所有L2类目
        MarketCategoryExample categoryExample = new MarketCategoryExample();
        categoryExample.createCriteria().andPidEqualTo(id);
        List<MarketCategory> categoryList = marketCategoryMapper.selectByExample(categoryExample);
        CatalogCurrentVo catalogCurrentVo = new CatalogCurrentVo(marketCategory, categoryList);
        return catalogCurrentVo;
    }
}
